package tdd.refactor;

public class BaseFeeOuter implements Chargeable{
	BaseFee baseFee;
	double oldStartMiles;
	public BaseFeeOuter(TaxiFeeModel taxiFeeModel, double oldStartMiles) {
		baseFee = new BaseFee(taxiFeeModel);
		this.oldStartMiles = oldStartMiles;
	}

	public double chargeByMiles(double miles){
		double deductions = (Math.ceil(miles) - (baseFee.taxiFeeModel.startMiles - this.oldStartMiles))*baseFee.taxiFeeModel.pricePerMile;
		if (miles < (baseFee.taxiFeeModel.startMiles - this.oldStartMiles)) {
			return 0;
		} else {
			return  Math.ceil(miles) <= baseFee.taxiFeeModel.startMiles? 
					baseFee.taxiFeeModel.startPrice - deductions: 
					baseFee.taxiFeeModel.startPrice - deductions +(Math.ceil(miles) - baseFee.taxiFeeModel.startMiles)*baseFee.taxiFeeModel.pricePerMile;
		}
	}

}
